-- HexX Scoreboard Editor for Sider.
-- Intially Written by Mohamed2746, Update and researched by afandix.
-- This version is designed for the Afandix Premier League scoreboard.
-- Version 1.0.4
-----------------------------
-- No longer reads config.txt file on kitserver (except some parts of unicolor1 or 2 by game, you have to adjust it manually.).
-- The config colors are located in the "colors.ini" file in the "content\scoreboard-hexx\team_colors" folder.
-- [team id] Any team names
-- kit id (0=1st, 1=2nd, 2=3rd or more) = #plate color, #plate2 color, #text color, #shape color, #shape2 color, #text shape color
-- example:
-- [100] Manchester United
-- 0 = #bd1324, #771e0c, #ffffff, #bd1324, #771e0c, #ffffff
-- **Some notes:
-- There is still a bug with the away line-up colors.
-- Team color changes on goal cards may be incorrect due to late stats.
-- Changing textures or editing scoreboard files may cause some script functions to not work normally. Using some of these scoreboard files with other league scoreboards will also cause that or possibly crash.

local m = {}

local colors
local home_cfg
local away_cfg
local wave0_enter
local wave1_enter
local wave2_enter
local wave3_enter
-- local wave4_enter
-- local wave5_enter
local homeName_enter
local awayName_enter
local lineupShape_enter
local lineupName_enter
local wave0
local wave1
local wave2
local wave3
-- local wave4
-- local wave5
local homeName
local awayName
local tv
local statsHome
local statsAway
local statsHome2
local statsAway2
local statsHome3
local statsAway3
local goalShape
local goalShape2
local goalName
local CardTime
local CardScorer
local CardTeamLogo
local wave0_result
local wave1_result
local wave2_result
local wave3_result
-- local wave4_result
-- local wave5_result
local homeName_result
local awayName_result
local wave0_pk
local wave1_pk
local wave2_pk
local wave3_pk
-- local wave4_pk
-- local wave5_pk
local homeName_pk
local awayName_pk
local homePause
local awayPause

local function load_ini(ctx, ini_name)
    log(string.format("Loading %s", ini_name))
    local t = {}
    local f = io.open(ctx.sider_dir .. "content\\scoreboard-hexx\\" .. ini_name)
    if f then
        for line in f:lines() do
            if not string.match(line, "[SET]") then
                local index, value = string.match(line, "%s*([%w_]+)%s*=%s*[\"]?([^\"]*)")
                if index and value then
                    -- value = tonumber(value) or value
                    index = tonumber(index) or index
                    t[index] = value
                end
            end
        end
    end
    return t
end

local function load_colors(ctx, ini_name)
    log(string.format("Loading %s", ini_name))
    local t = {}
    local f = io.open(ctx.sider_dir .. "content\\scoreboard-hexx\\" .. ini_name)
    local current_team_id
    local current_team_name
    if f then
        for line in f:lines() do
            local team_id, team_name = string.match(line, "^%[(%d+)%]%s*(.-)$")
            if team_id then
                current_team_id = team_id
                current_team_name = team_name
                t[current_team_id] = {name = current_team_name, kits = {}}
            else
                local kit_id, plate_clr, plate2_clr, text_clr, shape_clr, shape2_clr, text_shape_clr = string.match(line, "(%d+) = (#%x+), (#%x+), (#%x+), (#%x+), (#%x+), (#%x+)")
                if kit_id and plate_clr and plate2_clr and text_clr and shape_clr and shape2_clr and text_shape_clr then
                    t[current_team_id].kits[kit_id] = {plate_clr = plate_clr, plate2_clr = plate2_clr, text_clr = text_clr, shape_clr = shape_clr, shape2_clr = shape2_clr, text_shape_clr = text_shape_clr}
                end
            end
        end
        f:close()
    else
        log("Error: Unable to open " .. ini_name)
    end
    return t
end

local function colorHexToBytes(colorHex)
    return memory.pack("u8", tonumber(colorHex:sub(2, 3), 16)) ..
        memory.pack("u8", tonumber(colorHex:sub(4, 5), 16)) .. memory.pack("u8", tonumber(colorHex:sub(6, 7), 16))
end

local function colorHexToLittleEndianBytes(colorHex)
    return memory.pack("u8", tonumber(colorHex:sub(6, 7), 16)) ..
        memory.pack("u8", tonumber(colorHex:sub(4, 5), 16)) .. memory.pack("u8", tonumber(colorHex:sub(2, 3), 16))
end

-- define a function to get color
local function getColor(team_id, kit_id, color_type)
    local team = colors[tostring(team_id)]
    local kit = team and team.kits[tostring(kit_id)]
    return kit and kit[color_type]
end

local function getColorFunction(color_type)
    return function(team_id, kit_id)
        return getColor(team_id, kit_id, color_type)
    end
end

-- generate get color functions
local plateClr = getColorFunction("plate_clr")
local plate2Clr = getColorFunction("plate2_clr")
local textClr = getColorFunction("text_clr")
local shapeClr = getColorFunction("shape_clr")
local shape2Clr = getColorFunction("shape2_clr")
local textShapeClr = getColorFunction("text_shape_clr")

-- define a function to write color
local function writeColorFunction(color_type)
    return function(data, colorAddresses, team_id, kit_id)
        local colorHex = getColor(team_id, kit_id, color_type)
        if colorHex then
            for n = 1, #colorAddresses do
                memory.write(data + tonumber(colorAddresses[n], 16), colorHexToBytes(colorHex))
            end
        end
    end
end

-- generate write color functions
local writePlateClr = writeColorFunction("plate_clr")
local writePlate2Clr = writeColorFunction("plate2_clr")
local writeTextClr = writeColorFunction("text_clr")
local writeShapeClr = writeColorFunction("shape_clr")
local writeShape2Clr = writeColorFunction("shape2_clr")
local writeTextShapeClr = writeColorFunction("text_shape_clr")

-- get team and kit IDs
function get_team_kit_ids(ctx)
    local home_team_id = ctx.home_team
    local home_kit_id = ctx.kits.get_current_kit_id(0)
    local away_team_id = ctx.away_team
    local away_kit_id = ctx.kits.get_current_kit_id(1)

    return home_team_id, home_kit_id, away_team_id, away_kit_id
end

-- check if the tournament ID is correct
function EPL(ctx)
	return ctx.tournament_id == 17 or (ctx.tournament_id == 65535 and ctx.common_lib.tid_same_league(ctx.home_team, ctx.away_team) == 17)
end

-- search start address for .bin in memory address
local startAddress = 0x00007FF4D4400000
local endAddress = 0x00007FF4FFA00000

local game2dEnglandEnterAddress, game2dEnglandAddress

function resetSearch()
	game2dEnglandEnterAddress = nil
    game2dEnglandAddress = nil
end

function searchStr(homeColorStr, type)
    local searchStr, foundAddress

    if type == "lineup" then
        searchStr = "\x00\x07\x0a\x00\x00\x1b\xf5\xff\xff\x00" .. homeColorStr
    elseif type == "goalplate" then
        searchStr = "\x14\x00\xc0\x1f\x0d\x24\x00\x00\x02\x00\x9f\x00\x5b\xd1\xff\xff\xe6\xf9\xff\xff\xff\x4f\x04\xfb"
    end

    if type == "lineup" or type == "goalplate" then
        foundAddress = memory.safe_search(searchStr, startAddress, endAddress)
    end

    if foundAddress and type == "lineup" then
        game2dEnglandEnterAddress = foundAddress - 0x1307A
		log("game2dEnglandEnter.bin Address: " .. string.format("0x%x", tonumber(ffi.cast("intptr_t", game2dEnglandEnterAddress))))
    elseif foundAddress and type == "goalplate" then
        game2dEnglandAddress = foundAddress - 0x6663
		log("game2dEngland.bin Address: " .. string.format("0x%x", tonumber(ffi.cast("intptr_t", game2dEnglandAddress))))
    end
end

-- changed the away colors for the line-up
function changeColorAway(team, team_id, kit_id, lineupShape_enter, lineupName_enter)
    local function changeColor(colorFunction, offsets)
        local colorStr = colorHexToLittleEndianBytes(colorFunction(team_id, kit_id))
        for _, offset in ipairs(offsets) do
            local addr = game2dEnglandEnterAddress + tonumber(offset, 16)
            memory.write(addr, colorStr)
        end
    end

    changeColor(shapeClr, lineupShape_enter)
    changeColor(textShapeClr, lineupName_enter)
end

-- change team colors for goalcard
function changeGoalColor(team_id, kit_id, goalShape, goalShape2, goalName)
    local function changeColor(colorFunction, offsets)
        local colorStr = colorHexToLittleEndianBytes(colorFunction(team_id, kit_id))
        for _, offset in ipairs(offsets) do
            local addr = game2dEnglandAddress + tonumber(offset, 16)
            memory.write(addr, colorStr)
        end
    end

    changeColor(plateClr, goalShape)
    changeColor(plate2Clr, goalShape2)
    changeColor(textClr, goalName)
end

-- function to check goal score and change scorer texture
local prev_home_score, prev_away_score = 0, 0

function check_goal_score(ctx, stats, home_team_id, home_kit_id, away_team_id, away_kit_id)
	if match.stats() and EPL(ctx) and game2dEnglandAddress then
        local home_score, away_score = stats.home_score, stats.away_score
        local period = stats.period
        local minutes = stats.clock_minutes
        local seconds = stats.clock_seconds
        local add_minutes = stats.added_minutes

        if home_score > prev_home_score then
            changeGoalColor(home_team_id, home_kit_id, goalShape, goalShape2, goalName)
            resetHalftime("\xba\x3a\xff\xff\x99\x51\x00\x00")
            changeScorer(home_score, away_score, "\x18\xfc\xfe\xff")
            moveLogo("\xa7\x01\x00\x00")
        end

        if away_score > prev_away_score then
            changeGoalColor(away_team_id, away_kit_id, goalShape, goalShape2, goalName)
            resetHalftime("\xba\x3a\xff\xff\x99\x51\x00\x00")
            changeScorer(home_score, away_score, "\x15\x55\xff\xff")
            moveLogo("\xa7\x01\x00\x00")
        end
		
		-- change team logo position when injury time
		if add_minutes then
			if period == 1 and (minutes >= 45 + add_minutes) then
				moveLogo("\x7d\x03\x00\x00")
				-- log("add minute first")
			elseif period == 2 and (minutes >= 90 + add_minutes) then
				moveLogo("\x7d\x03\x00\x00")
				-- log("add minute second")
			elseif period == 3 and (minutes >= 105 + add_minutes) then
				HalfTime(stats)
				-- log("add minute Extra 1st")
			elseif period == 4 and (minutes >= 120 + add_minutes) then
				moveLogo("\x7d\x03\x00\x00")
				-- log("add minute Extra 2nd")
			end
		end

        prev_home_score, prev_away_score = home_score, away_score
    end
end

-- change first half or second half for gamecard
function change1st2nd(str)
    for _, offset in ipairs(CardTime) do
        local addr = game2dEnglandAddress - 0x1 + tonumber(offset, 16)
        memory.write(addr, str)
    end
end

-- change halftime or fulltime for gamecard
function changeHalftime(home_score, away_score, str1, str2)
    for _, offset in ipairs(CardTime) do
        local addr = game2dEnglandAddress - 0x1 + tonumber(offset, 16)
        if home_score <= 1 and away_score <= 1 then
            memory.write(addr, str1)
        elseif home_score > 1 or away_score > 1 then
            memory.write(addr, str2)
        end
    end
end

function resetHalftime(str)
    for _, offset in ipairs(CardTime) do
        local addr = game2dEnglandAddress - 0x1 + tonumber(offset, 16)
        memory.write(addr, str)
    end
end

-- change scorer texture home or away for gamecard
function changeScorer(home_score, away_score, str)
    for _, offset in ipairs(CardScorer) do
        local addr = game2dEnglandAddress - 0x1 + tonumber(offset, 16)
        if home_score > prev_home_score then
            memory.write(addr, str)
        elseif away_score > prev_away_score then
            memory.write(addr, str)
        end
    end
end

function resetScorer(str)
    for _, offset in ipairs(CardScorer) do
        local addr = game2dEnglandAddress - 0x1 + tonumber(offset, 16)
        memory.write(addr, str)
    end
end

-- change position team logo home or away for gamecard
function moveLogo(str)
    for _, offset in ipairs(CardTeamLogo) do
        local addr = game2dEnglandAddress - 0x1 + tonumber(offset, 16)
        memory.write(addr, str)
    end
end

-- randomize tv logo
local tv_str = {
	vidio = "\x02\x4c\x0e\x29\x04\x98\x16\x15",
	bein = "\x04\x98\x0e\x29\x06\xe4\x16\x15",
	cbssports = "\x06\xe4\x0e\x29\x09\x30\x16\x15",
	dazn = "\x09\x30\x0e\x29\x0b\x7c\x16\x15",
	directsports = "\x0b\x7c\x0e\x29\x0d\xc8\x16\x15",
	peacock = "\x0d\xc8\x0e\x29\x10\x14\x16\x15",
	primevideo= "\x10\x14\x0e\x29\x12\x60\x16\x15",
	tntsports = "\x12\x60\x0e\x29\x14\xac\x16\x15",
	skysports = "\x14\xac\x0e\x29\x16\xf8\x16\x15",
	arenasport = "\x16\xf8\x0e\x29\x19\x44\x16\x15",
	optussport = "\x19\x44\x0e\x29\x1b\x90\x16\x15",
	canalplus = "\x1b\x90\x0e\x29\x1d\xdc\x16\x15",
	notv = "\x00\x00\x0e\x29\x02\x4c\x16\x15"
}

local function writeStr(fileaddress, strAddresses, str)
    for n = 1, #strAddresses do
        memory.write(fileaddress + tonumber(strAddresses[n], 16), str)
    end
end

function randomtv()
    local keys = {}
    for key in pairs(tv_str) do
        table.insert(keys, key)
    end
    local randomKey = keys[math.random(#keys)]
    local str = tv_str[randomKey]

    log("TV network chosen: " .. randomKey)
    return str
end

-- change the stats bar color (Change the color of the image hex code directly)
-- **Caution: If the image changes, the code function will fail and cause color errors in the texture. (You have to look for the exact color code location again) -- Update error fixed if it's not that file then this function will stop.
function colorHexToBytes2(colorHex)
    return memory.pack("u8", tonumber(colorHex:sub(2, 3), 16)) ..
        memory.pack("u8", tonumber(colorHex:sub(4, 5), 16)) ..
        memory.pack("u8", tonumber(colorHex:sub(6, 7), 16)) ..
        memory.pack("u8", tonumber(colorHex:sub(8, 9), 16))  -- pack the fourth byte
end

function modifyColor(colorHex, additionHex, position)
	-- insert the additional hexadecimal value at the specified position
    return colorHex:sub(1, position-1) .. additionHex .. colorHex:sub(position)
end

function colorStatsImage(color_type, additionHex, position)
     return function(data, colorAddresses, team_id, kit_id)
         local colorHex = getColor(team_id, kit_id, color_type)
         if colorHex then
             local modifiedColorHex = modifyColor(colorHex, additionHex, position)
             for n = 1, #colorAddresses do
                 memory.write(data + tonumber(colorAddresses[n], 16), colorHexToBytes2(modifiedColorHex))
             end
         end
     end
 end

-- insert code between color codes, example: #8ab8e6 to 8ab801e6 or 8a03b8e6
local statsClr01 = colorStatsImage("shape_clr", '01', 6) -- Add 01 to the fifth
local statsClr03 = colorStatsImage("shape_clr", '03', 4) -- Add 03 to the third

function EnterScreen(data, home_team_id, home_kit_id, away_team_id, away_kit_id)
    writePlateClr(data, wave1_enter, home_team_id, home_kit_id)
    writePlateClr(data, wave0_enter, away_team_id, away_kit_id)
    writePlate2Clr(data, wave3_enter, home_team_id, home_kit_id)
    writePlate2Clr(data, wave2_enter, away_team_id, away_kit_id)
    writeTextClr(data, homeName_enter, home_team_id, home_kit_id)
    writeTextClr(data, awayName_enter, away_team_id, away_kit_id)
    writeShapeClr(data, lineupShape_enter, home_team_id, home_kit_id)
    writeTextShapeClr(data, lineupName_enter, home_team_id, home_kit_id)
end

function Scoreboards(data, home_team_id, home_kit_id, away_team_id, away_kit_id)
    writePlateClr(data, wave1, home_team_id, home_kit_id)
    writePlateClr(data, wave0, away_team_id, away_kit_id)
    writePlate2Clr(data, wave3, home_team_id, home_kit_id)
    writePlate2Clr(data, wave2, away_team_id, away_kit_id)
    writeTextClr(data, homeName, home_team_id, home_kit_id)
    writeTextClr(data, awayName, away_team_id, away_kit_id)
    writePlateClr(data, goalShape, home_team_id, home_kit_id)
    writePlate2Clr(data, goalShape2, home_team_id, home_kit_id)
    writeTextClr(data, goalName, home_team_id, home_kit_id)
end

function LineupScreen(away_team_id, away_kit_id, lineupShape_enter, lineupName_enter)
	changeColorAway("away", away_team_id, away_kit_id, lineupShape_enter, lineupName_enter)
end

function FirstTime()
	change1st2nd("\xc8\xff\xff\xff\x16\xfd\xfe\xff")
	moveLogo("\x7d\x03\x00\x00")
	-- log("First Half")
end

function HalfTime(stats)
	moveLogo("\x7d\x03\x00\x00")
	resetScorer("\xf6\x01\x00\x00")
	changeHalftime(stats.home_score, stats.away_score, "\xba\x3a\xff\xff\x32\xac\xff\xff", "\xba\x3a\xff\xff\x16\xac\xff\xff")
	-- log("Half Time")
end

function FullTime(stats)
	resetScorer("\xf6\x01\x00\x00")
	changeHalftime(stats.home_score, stats.away_score, "\xc8\xff\xff\xff\x32\xac\xff\xff", "\xc8\xff\xff\xff\x16\xac\xff\xff")
	moveLogo("\x7d\x03\x00\x00")
	-- log("Full Time")
end

function SecondTime()
	change1st2nd("\xc8\xff\xff\xff\xf7\x55\xff\xff")
	moveLogo("\x7d\x03\x00\x00")
	-- log("Second Half")
end

function PauseMenuScreen(data, homePause, home_team_id, home_kit_id, awayPause, away_team_id, away_kit_id)
	writeShapeClr(data, homePause, home_team_id, home_kit_id)
	writeShapeClr(data, awayPause, away_team_id, away_kit_id)
end

function ResultScreen(data, wave1_result, home_team_id, home_kit_id, wave0_result, away_team_id, away_kit_id, wave3_result, wave2_result, homeName_result, awayName_result)
    writeShapeClr(data, wave1_result, home_team_id, home_kit_id)
    writeShapeClr(data, wave0_result, away_team_id, away_kit_id)
    writeShape2Clr(data, wave3_result, home_team_id, home_kit_id)
    writeShape2Clr(data, wave2_result, away_team_id, away_kit_id)
    writeTextShapeClr(data, homeName_result, home_team_id, home_kit_id)
    writeTextShapeClr(data, awayName_result, away_team_id, away_kit_id)
end

function PenaltyScreen(data, wave1_pk, home_team_id, home_kit_id, wave0_pk, away_team_id, away_kit_id, wave3_pk, wave2_pk, homeName_pk, awayName_pk)
    writePlateClr(data, wave1_pk, home_team_id, home_kit_id)
    writePlateClr(data, wave0_pk, away_team_id, away_kit_id)
    writePlate2Clr(data, wave3_pk, home_team_id, home_kit_id)
    writePlate2Clr(data, wave2_pk, away_team_id, away_kit_id)
    writeTextClr(data, homeName_pk, home_team_id, home_kit_id)
    writeTextClr(data, awayName_pk, away_team_id, away_kit_id)
end

function ColorStats(data, statsHome, home_team_id, home_kit_id, statsAway, away_team_id, away_kit_id, statsHome2, statsAway2, statsHome3, statsAway3)
	writeShapeClr(data, statsHome, home_team_id, home_kit_id)
	writeShapeClr(data, statsAway, away_team_id, away_kit_id)
	statsClr01(data, statsHome2, home_team_id, home_kit_id)
	statsClr01(data, statsAway2, away_team_id, away_kit_id)
	statsClr03(data, statsHome3, home_team_id, home_kit_id)
	statsClr03(data, statsAway3, away_team_id, away_kit_id)
end

-- afandix special codes in bin files
local Afandix = "\x78\x2E\x61\x70\x6B"

function AfandixTV(ctx, filename, data)
	return string.match(filename, "game2dEngland.bin") and memory.read(data + 0xc, 4) == "\xe5\xac\x5e\x00" -- Specific file size for random tv logos texture, otherwise it will be used from the scoreboard server
end

function AfandixBars(ctx, filename, data)
	return string.match(filename, "game2dEngland.bin") and memory.read(data + 0x1e05ea, 3) == "\xaf\xaf\xaf" -- Specific hex color code in the image**
end

function m.data_ready(ctx, filename, data, size, total_size, offset, cpk_filename)
    data = tostring(data):sub(11, -1)
	
    local home_team_id, home_kit_id, away_team_id, away_kit_id = get_team_kit_ids(ctx)
	
    local stats = match.stats()
	check_goal_score(ctx, stats, home_team_id, home_kit_id, away_team_id, away_kit_id)

    -- Check filename and modify data accordingly
    if string.match(filename, "game2dEnglandEnter.bin") and memory.read(data + 0x2a, 5) == Afandix then
		EnterScreen(data, home_team_id, home_kit_id, away_team_id, away_kit_id)
    elseif string.match(filename, "game2dEngland.bin") and memory.read(data + 0x25, 5) == Afandix then
		Scoreboards(data, home_team_id, home_kit_id, away_team_id, away_kit_id)
		if AfandixTV(ctx, filename, data) then
			writeStr(data, tv, randomtv())
		end
		if AfandixBars(ctx, filename, data) then
			ColorStats(data, statsHome, home_team_id, home_kit_id, statsAway, away_team_id, away_kit_id, statsHome2, statsAway2, statsHome3, statsAway3)
		end
	elseif string.match(filename, "licenceTextureEngland.bin") and memory.read(data + 0x2d, 5) == Afandix then
        searchStr(colorHexToLittleEndianBytes(shapeClr(home_team_id, home_kit_id)), "lineup")
        searchStr(colorHexToLittleEndianBytes(plateClr(home_team_id, home_kit_id)), "goalplate")
	end
    if string.match(filename, "ent_022_pl_cmn_home.fdc") and EPL(ctx) then
		LineupScreen(away_team_id, away_kit_id, lineupShape_enter, lineupName_enter)
	elseif string.match(filename, "ent_.*_cmn_cam.fdc") or string.match(filename, "ENG1wipe.usm") or string.match(filename, "MatchStatsResult.json") and EPL(ctx) then
		FirstTime()
	elseif string.match(filename, "tu_half_cmn.*cam.*st.*.fdc") and EPL(ctx) then
		HalfTime(stats)
	elseif string.match(filename, "tu_full_.*_cut_st.*.fdc") or string.match(filename, "tu_pickup_good_.*_cam.fdc") or string.match(filename, "tu_pickup_cmn_.*_cam_st.*.fdc") and EPL(ctx) then
		FullTime(stats)
	elseif string.match(filename, "MatchHalfTime.json") and EPL(ctx) then
		SecondTime()
	end
	if string.match(filename, "pauseMenu.bin") and memory.read(data + 0x21, 5) == Afandix then
		PauseMenuScreen(data, homePause, home_team_id, home_kit_id, awayPause, away_team_id, away_kit_id)
	elseif string.match(filename, "resultTeamRecordEngland.bin") and memory.read(data + 0x2f, 5) == Afandix then
        ResultScreen(data, wave1_result, home_team_id, home_kit_id, wave0_result, away_team_id, away_kit_id, wave3_result, wave2_result, homeName_result, awayName_result)
    elseif string.match(filename, "game2dEnglandPk.bin") and memory.read(data + 0x27, 5) == Afandix then
        PenaltyScreen(data, wave1_pk, home_team_id, home_kit_id, wave0_pk, away_team_id, away_kit_id, wave3_pk, wave2_pk, homeName_pk, awayName_pk)
	end
	if string.match(filename, "MatchDiscontinue.*.json") or string.match(filename, "MatchEnd.json") and EPL(ctx) then
		resetSearch()
    end
end

function m.init(ctx)
    ctx.register("livecpk_data_ready", m.data_ready)
	colors = load_colors(ctx, "team_colors\\colors.ini")
    wave0_enter = load_ini(ctx, "game2dEnglandEnter_bin\\Waves0_enter.ini")
    wave1_enter = load_ini(ctx, "game2dEnglandEnter_bin\\Waves1_enter.ini")
    wave2_enter = load_ini(ctx, "game2dEnglandEnter_bin\\Waves2_enter.ini")
    wave3_enter = load_ini(ctx, "game2dEnglandEnter_bin\\Waves3_enter.ini")
    -- wave4_enter = load_ini(ctx, "game2dEnglandEnter_bin\\Waves4_enter.ini") -- as competition logo
    -- wave5_enter = load_ini(ctx, "game2dEnglandEnter_bin\\Waves5_enter.ini") -- not use
    homeName_enter = load_ini(ctx, "game2dEnglandEnter_bin\\home_txt_enter.ini")
    awayName_enter = load_ini(ctx, "game2dEnglandEnter_bin\\away_txt_enter.ini")
    lineupShape_enter = load_ini(ctx, "game2dEnglandEnter_bin\\Lineup_shape_enter.ini")
    lineupName_enter = load_ini(ctx, "game2dEnglandEnter_bin\\Lineup_txt_enter.ini")
    wave0 = load_ini(ctx, "game2dEngland_bin\\Waves0.ini")
    wave1 = load_ini(ctx, "game2dEngland_bin\\Waves1.ini")
    wave2 = load_ini(ctx, "game2dEngland_bin\\Waves2.ini")
    wave3 = load_ini(ctx, "game2dEngland_bin\\Waves3.ini")
    -- wave4 = load_ini(ctx, "game2dEngland_bin\\Waves4.ini") -- as competition logo
    -- wave5 = load_ini(ctx, "game2dEngland_bin\\Waves5.ini") -- not use
    homeName = load_ini(ctx, "game2dEngland_bin\\home_txt.ini")
    awayName = load_ini(ctx, "game2dEngland_bin\\away_txt.ini")
    CardTime = load_ini(ctx, "game2dEngland_bin\\cardtime.ini")
	CardScorer = load_ini(ctx, "game2dEngland_bin\\cardscorer.ini")
	CardTeamLogo = load_ini(ctx, "game2dEngland_bin\\cardteamlogo.ini")
    goalShape = load_ini(ctx, "game2dEngland_bin\\goal_shape.ini")
    goalShape2 = load_ini(ctx, "game2dEngland_bin\\goal_shape2.ini")
    goalName = load_ini(ctx, "game2dEngland_bin\\goal_txt.ini")
	tv = load_ini(ctx, "game2dEngland_bin\\broadcast_tv.ini")
	statsHome = load_ini(ctx, "game2dEngland_bin\\stats_home.ini")
	statsAway = load_ini(ctx, "game2dEngland_bin\\stats_away.ini")
	statsHome2 = load_ini(ctx, "game2dEngland_bin\\stats_home2.ini")
	statsAway2 = load_ini(ctx, "game2dEngland_bin\\stats_away2.ini")
	statsHome3 = load_ini(ctx, "game2dEngland_bin\\stats_home3.ini")
	statsAway3 = load_ini(ctx, "game2dEngland_bin\\stats_away3.ini")
    wave0_result = load_ini(ctx, "resultTeamRecordEngland_bin\\Waves0_result.ini")
    wave1_result = load_ini(ctx, "resultTeamRecordEngland_bin\\Waves1_result.ini")
    wave2_result = load_ini(ctx, "resultTeamRecordEngland_bin\\Waves2_result.ini")
    wave3_result = load_ini(ctx, "resultTeamRecordEngland_bin\\Waves3_result.ini")
    -- wave4_result = load_ini(ctx, "resultTeamRecordEngland_bin\\Waves4_result.ini") -- as competition logo
    -- wave5_result = load_ini(ctx, "resultTeamRecordEngland_bin\\Waves5_result.ini") -- not use
    homeName_result = load_ini(ctx, "resultTeamRecordEngland_bin\\home_txt_result.ini")
    awayName_result = load_ini(ctx, "resultTeamRecordEngland_bin\\away_txt_result.ini")
    wave0_pk = load_ini(ctx, "game2dEnglandPK_bin\\Waves0_pk.ini")
    wave1_pk = load_ini(ctx, "game2dEnglandPK_bin\\Waves1_pk.ini")
    wave2_pk = load_ini(ctx, "game2dEnglandPK_bin\\Waves2_pk.ini")
    wave3_pk = load_ini(ctx, "game2dEnglandPK_bin\\Waves3_pk.ini")
    -- wave4_pk = load_ini(ctx, "game2dEnglandPK_bin\\Waves4_pk.ini") -- as competition logo
    -- wave5_pk = load_ini(ctx, "game2dEnglandPK_bin\\Waves5_pk.ini") -- not use
    homeName_pk = load_ini(ctx, "game2dEnglandPK_bin\\home_txt_pk.ini")
    awayName_pk = load_ini(ctx, "game2dEnglandPK_bin\\away_txt_pk.ini")
    homePause = load_ini(ctx, "pauseMenu_bin\\home_shape.ini")
    awayPause = load_ini(ctx, "pauseMenu_bin\\away_shape.ini")
end

return m
